import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: '首页',
        component: () => import('@/views/home/index.vue'),
        meta: { title: '首页', icon: 'fa-solid fa-house' }
      },
      {
        path: 'course',
        name: '课程中心',
        component: () => import('@/views/course/index.vue'),
        meta: { title: '课程', icon: 'fa-solid fa-layer-group' }
      },
      {
        path: 'vocabulary',
        name: '词库中心',
        component: () => import('@/views/vocabulary/index.vue'),
        meta: { title: '词库', icon: 'fa-solid fa-book' }
      },
      {
        path: 'student',
        name: '学生中心',
        component: () => import('@/views/student/index.vue'),
        meta: { title: '学生', icon: 'fa-solid fa-graduation-cap' }
      },
      {
        path: 'notice',
        name: '通知中心',
        component: () => import('@/views/notify/index.vue'),
        meta: { title: '通知', icon: 'fa-solid fa-bell' }
      },
      {
        path: 'personal',
        name: '个人中心',
        component: () => import('@/views/myself/index.vue'),
        meta: { title: '个人中心', icon: 'fa-solid fa-user' },
        hidden: true // 顶部菜单不显示
      },
      {
        path: 'safety',
        name: '安全中心',
        component: () => import('@/views/myself/safety.vue'),
        meta: { title: '安全中心', icon: 'fa-solid fa-user' },
        hidden: true // 顶部菜单不显示
      },
      {
        path: '/security/account',
        name: '设置账户',
        component: () => import('@/views/myself/security/AccountSetupWizard.vue'),
        hidden: true // 顶部菜单不显示
      },
      {
        path: '/security/password',
        name: '修改密码',
        component: () => import('@/views/myself/security/PasswordSetupWizard.vue'),
        hidden: true // 顶部菜单不显示
      },
      {
        path: '/security/phone',
        name: '修改手机号',
        component: () => import('@/views/myself/security/PhoneSetupWizard.vue'),
        hidden: true // 顶部菜单不显示
      },
      {
        path: '/security/email',
        name: '修改邮箱',
        component: () => import('@/views/myself/security/EmailSetupWizard.vue'),
        hidden: true // 顶部菜单不显示
      }
    ]
  },

  {
    path: '/traditionalTeaching',
    name: '传统模式授课',
    component: () => import('@/views/course/component/courseTeach/traditionalTeaching.vue'),
    hidden: true // 顶部菜单不显示
  },
  {
    path: '/afterClass',
    name: '课后反馈',
    component: () => import('@/views/course/component/courseTeach/AfterClass.vue'),
    hidden: true // 顶部菜单不显示
  },
  {
    path: '/print',
    name: '课后打印',
    component: () => import('@/views/course/classHistory/component/WordReviewPrint.vue'),
    hidden: true // 顶部菜单不显示
  },
  {
    path: '/antiForget',
    name: '抗遗忘页面',
    component: () => import('@/views/course/component/courseTeach/wordLearning/AntiForgetReview.vue'),
    hidden: true // 顶部菜单不显示
  },
  {
    path: '/antiForgetFeedback',
    name: '抗遗忘反馈页面',
    component: () => import('@/views/course/component/courseTeach/AntiForgetAfter.vue'),
    hidden: true // 顶部菜单不显示
  },
  {
    path: '/vocabularyTestHome',
    name: '词汇量测试',
    component: () => import('@/views/vocabulary/component/VocabularyTestHome.vue'),
    hidden: true // 顶部菜单不显示
  },
  {
    path: '/vocabTestStart',
    name: '词汇量测试',
    component: () => import('@/views/vocabulary/component/VocabTestStart.vue'),
    hidden: true // 顶部菜单不显示
  },
  {
    path: '/VocabTestResult',
    name: 'VocabTestResult',
    component: () => import('@/views/vocabulary/component/VocabTestResult.vue'),
    // 定义路由参数（等级和词汇量）
    props: route => ({
      level: route.query.level, // 从URL查询参数中获取等级（如 B1）
      vocabCount: route.query.vocabCount // 从URL查询参数中获取词汇量（如 4500）
    })
  },
  {
    path: '/raedTrain',
    name: '阅读等级选择',
    component: () => import('@/views/readTrain/index.vue')
  },
  {
    path: '/raedTrainGrade',
    name: '阅读等级文章分类',
    component: () => import('@/views/readTrain/gradePassagePage.vue')
  },
  {
    path: '/raedStudyPage',
    name: '阅读学习界面',
    component: () => import('@/views/readTrain/raedStudyPage.vue')
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
